<template>
  <div class="">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="(item, index) in detail.pics" :key="index">
        <img :src="item.pics_mid_url" alt="" />
      </van-swipe-item>
    </van-swipe>
    <van-action-bar>
      <van-action-bar-icon icon="chat-o" text="客服" />
      <van-action-bar-icon icon="shop-o" text="店铺" />
      <van-action-bar-button color="#be99ff" type="warning" @click="add" text="加入购物车" />
      <van-action-bar-button color="#7232dd" type="danger" text="立即购买" />
    </van-action-bar>
  </div>
</template>

<script>
import axios from "axios";
import { ref, reactive, toRefs } from "vue";
import { useRoute,useRouter } from "vue-router";
import { useStore } from 'vuex';
export default {
  setup() {
    const route = useRoute();
    const store = useStore();
    const router = useRouter();
    let id = route.query.id;
    console.log(id);
    const data = reactive({
      detail: {},
    });
    axios
      .get(
        `https://api-hmugo-web.itheima.net/api/public/v1/goods/detail?goods_id=${id}`
      )
      .then((res) => {
        data.detail = res.data.message;
      });
      const add = () => {
        let obj = {
          name: data.detail.goods_name,
          num: 1,
          url: data.detail.goods_big_logo,
          isCheck: false,
          id: data.detail.goods_id,
          price: data.detail.cat_one_id
        }
        store.commit('addCart', obj);
        router.push('/cart');
      }
    return {
      ...toRefs(data),
      add
    };
  },
};
</script>
<style lang="scss" scoped>
</style>